/*
 * @Author: Leo.wang wanglizhigs@163.com
 * @Date: 2024-06-04 22:46:30
 * @LastEditors: Leo.wang wanglizhigs@163.com
 * @LastEditTime: 2024-06-16 17:00:55
 * @FilePath: /chat-ai-plus/src/store/modules/robot copy.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { defineStore } from 'pinia';
import { sleep } from '@/utils/utility';
import {
  createInstruction,
  getInstruction,
  updateInstruction,
  getTopInstructionList,
  getInstructionList,
  deleteTopInstructionList,
} from '@/api/instruction.api'

const useInstructionStore = defineStore<StoreState>({
  id: 'instructionStore',
  state: () => ({
    instructionList: [],
    topInstructionList: []
  }),
  getters: {
  },
  actions: {
    async getTopInstructionList() {
      const response = await getTopInstructionList();
      const { data } = response;
      this.topInstructionList = data || [];

    },
    async getInstructionList(version: number) {
      const response = await getInstructionList(version);
      const { data } = response;
      this.instructionList = data || [];
    },

    async createInstruction(data, version) {
      const result = await createInstruction(data);
      this.getTopInstructionList();
      this.getInstructionList(version);
      return result;
    },
    async getInstruction(data) {
      const result = await getInstruction(data);

      return result;
    },

    async deleteTopInstructionList(id) {
      const result = await deleteTopInstructionList(id);
      return result;
    },
    async updateInstruction(data, version) {
      const result = await updateInstruction(data);
      this.getTopInstructionList();
      this.getInstructionList(version);
      return result;
    },
  },
});
export default useInstructionStore;